package qldc.pm.tienan.searchcontainer;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.portlet.PortletRequest;
import javax.portlet.PortletURL;

import qldc.pm.tienan.dto.DanhSachTienAnDTO;
import qldc.pm.tienan.constants.TienAnConstants;

import com.liferay.portal.kernel.dao.search.SearchContainer;

public class DSTienAnSearch extends SearchContainer<DanhSachTienAnDTO> {
	public static final String EMPTY_RESULTS_MESSAGE = "khong-tim-thay-nguoi-co-tien-an-nao";
	static List<String> headerNames = new ArrayList<String>();
	static Map<String, String> orderableHeaders = new HashMap<String, String>();
	static {

		orderableHeaders.put("ho-ten","ho-ten");
		orderableHeaders.put("so-dinh-danh-ca-nhan","so-dinh-danh-ca-nhan");

	}
	public DSTienAnSearch(PortletRequest portletRequest, PortletURL iteratorURL) {

		super(portletRequest, new DSTienAnDisplayTerms(portletRequest),
				new DSTienAnSearchTerms(portletRequest),
				DEFAULT_CUR_PARAM, DEFAULT_DELTA, iteratorURL, headerNames,
				EMPTY_RESULTS_MESSAGE);

		DSTienAnDisplayTerms displayTerms = (DSTienAnDisplayTerms) getDisplayTerms();

		SimpleDateFormat dateFormat = new SimpleDateFormat(TienAnConstants.DATE_PATTERN);


		if (displayTerms.getTuNgayToaAn() != null) {
			iteratorURL.setParameter(DSTienAnSearchTerms.TU_NGAY_TOA_AN,
					dateFormat.format(displayTerms.getTuNgayToaAn()));
		}

		if (displayTerms.getDenNgayToaAn() != null) {
			iteratorURL.setParameter(DSTienAnSearchTerms.DEN_NGAY_TOA_AN,
					dateFormat.format(displayTerms.getDenNgayToaAn()));
		}
		if (displayTerms.getTuNgayThongKe() != null) {
			iteratorURL.setParameter(DSTienAnSearchTerms.TU_NGAY_THONG_KE,
					dateFormat.format(displayTerms.getTuNgayThongKe()));
		}

		if (displayTerms.getDenNgayThongKe() != null) {
			iteratorURL.setParameter(DSTienAnSearchTerms.DEN_NGAY_THONG_KE,
					dateFormat.format(displayTerms.getDenNgayThongKe()));
		}
		if (displayTerms.getTuNgayXoaAnTich() != null) {
			iteratorURL.setParameter(DSTienAnSearchTerms.TU_NGAY_XOA_AN_TICH,
					dateFormat.format(displayTerms.getTuNgayXoaAnTich()));
		}

		if (displayTerms.getDenNgayXoaAnTich() != null) {
			iteratorURL.setParameter(DSTienAnSearchTerms.DEN_NGAY_XOA_AN_TICH,
					dateFormat.format(displayTerms.getDenNgayXoaAnTich()));
		}
		iteratorURL.setParameter(DSTienAnSearchTerms.TRANG_THAI,
				String.valueOf(displayTerms.getTrangThai()));
		iteratorURL.setParameter(DSTienAnDisplayTerms.TINH_ID,
				String.valueOf(displayTerms.getTinhId()));
		iteratorURL.setParameter(DSTienAnDisplayTerms.QUAN_HUYEN_ID,
				String.valueOf(displayTerms.getQuanHuyenId()));
		iteratorURL.setParameter(DSTienAnDisplayTerms.PHUONG_XA_ID,
				String.valueOf(displayTerms.getPhuongXaId()));

	}
}
